package cn.web.management.web.servlet.account;


import cn.web.management.service.inface.RegisteredUser;
import cn.web.management.service.impl.RegisteredUserImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "registeredServlet", value = "/registeredServlet")
public class registeredServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    /**
     * @description: 注册新用户的Servlet，保存新用户信息到数据库，之后转发给newUserServlet为其添加在线状态
     * @paramName: [req, resp]
     * @paramType: [javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse]
     * @returnType: void
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String employno = req.getParameter("employno");

        //将用户数据写入数据库
        RegisteredUser registeredUser = new RegisteredUserImpl();
        int count = registeredUser.addUser(username,password);

        //新建用户在线状态
        req.setAttribute("user","new");
        req.setAttribute("identity","user");
        req.getRequestDispatcher("newUserServlet").forward(req, resp);
    }
}
